home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / KEYBOARD.SWG / 0024_Simple KEYSTATE Routines.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-31  |  2KB  |  100 lines

  1. BB>procedure ShiftStatus(var Ins,
  2.   >                          CapsLock,
  3.   >                          NumLock,
  4.   >                          ScrollLock,
  5.   >                          Alt,
  6.   >                          Ctrl,
  7.   >                          LeftShift,
  8.   >                          RightShift: Boolean);
  9.  
  10. I thought this was a little tedious because it is a pain to have all
  11. those variables....so I made something like this:
  12.  
  13.  
  14. Unit KeyStats;
  15.  
  16. Interface
  17.  
  18.   Function RightShift: Boolean;
  19.   Function LeftShift: Boolean;
  20.   Function Control: Boolean;
  21.   Function Alt: Boolean;
  22.   Function ScrollLock: Boolean;
  23.   Function NumLock: Boolean;
  24.   Function CapsLock: Boolean;
  25.   Function Insert: Boolean;
  26.  
  27. Implementation
  28.  
  29. Uses Dos;
  30.  
  31. Function ShiftState: Byte;
  32. Var Regs: Registers;
  33. Begin
  34.   Regs.Ah:=2;
  35.   Intr($16, Regs);
  36.   ShiftState:=Regs.Al;
  37. End;
  38.  
  39. Function RightShift: Boolean;
  40. Begin
  41.   RightShift:=(ShiftState and 1)<>0;
  42. End;
  43.  
  44. Function LeftShift: Boolean;
  45. Begin
  46.   LeftShift:=(ShiftState and 2)<>0;
  47. End;
  48.  
  49. Function Control: Boolean;
  50. Begin
  51.   Control:=(ShiftState and 4)<>0;
  52. End;
  53.  
  54. Function Alt: Boolean;
  55. Begin
  56.   Alt:=(ShiftState and 8)<>0;
  57. End;
  58.  
  59. Function ScrollLock: Boolean;
  60. Begin
  61.   ScrollLock:=(ShiftState and 16)<>0;
  62. End;
  63.  
  64. Function NumLock: Boolean;
  65. Begin
  66.   NumLock:=(ShiftState and 32)<>0;
  67. End;
  68.  
  69. Function CapsLock: Boolean;
  70. Begin
  71.   CapsLock:=(ShiftState and 64)<>0;
  72. End;
  73.  
  74. Function Insert: Boolean;
  75. Begin
  76.   Insert:=(ShiftState and 128)<>0;
  77. End;
  78.  
  79. End.
  80.  
  81. Here is a little something that will turn on the light for you.
  82. The state of the keys below is at addrees $40 and offset $17 in memory, by
  83. changing the values at that location, you can turn on the CAPS, the NUM etc..
  84.  
  85.  
  86. Type
  87.  
  88.    Toggles      = (RShift, LShift, Ctrl, Alt,
  89.                    ScrollLock, NumLock, CapsLock, Insert);
  90.    Status       = Set of Toggles;
  91.  
  92. Var
  93.    KeyStatus   : Status Absolute $40:$17;
  94.  
  95.  
  96. Example : to turn on the caps lock, do this :
  97.  
  98.                         KeyStatus := KeyStatus + [CapsLock];
  99.  
  100.